import subprocess
import os
from tempfile import NamedTemporaryFile

def extract_audio(video_path: str) -> str:
    with NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
        output_path = temp_file.name
    
    ffmpeg_cmd = [
        "ffmpeg",
        "-y",
        "-i", video_path,
        "-vn",
        "-acodec", "pcm_s16le",
        "-ar", "16000",
        "-ac", "1",
        output_path
    ]
    
    try:
        subprocess.run(ffmpeg_cmd, check=True, capture_output=True)
        return output_path
    except subprocess.CalledProcessError as e:
        os.remove(output_path)
        raise RuntimeError(f"FFmpeg error: {e.stderr.decode()}")